package main

import (
	"sync"

	"github.com/go-resty/resty/v2"
)

// simulate
var G_AlphaExp = make(map[int]string)
var G_Client *resty.Client

var G_SimulateData []SimulateAlphaData = make([]SimulateAlphaData, 0, 0)
var G_SimulateSuperData []SimulateSuperData = make([]SimulateSuperData, 0, 0)

/*
var G_AlphaExpress []string
var G_AlphaDecay []int
var G_AlphaNeut []string
var G_AlphaRegion []string
var G_AlphaUniverse []string
*/

var G_WaitGroup sync.WaitGroup

// pnl
var G_ActiveAlphaPnl ActiveAlphaPnl
var G_ActiveAlpha = make(map[string]bool)

func Init() {

}

var G_RetryNum = 5

var G_Day []string = []string{
	"4",
	//"22",
	"66",
	//"126",
	//"252",
}

var G_MathOp []string = []string{
	"+",
	"-",
	"*",
	"/",
}

var G_BasicOp []string = []string{
	"reverse",
	"inverse",
	"rank",
	"zscore",
	"quantile",
	"normalize",
}

var G_TsOp []string = []string{
	"ts_rank",
	"ts_zscore",
	"ts_delta",
	"ts_delay",
	"ts_sum",
	"ts_product",
	"ts_std_dev",
	"ts_mean",
	"ts_arg_min",
	"ts_arg_max",
	"ts_scale",
	"ts_quantile",
	"ts_max",
	"ts_min",
}

var G_GroupOp []string = []string{
	"group_rank",
	"group_zscore",
	"group_neutralize",
	"group_scale",
	"group_max",
	"group_min",
}

var G_VecOp []string = []string{
	"vec_avg",
	"vec_max",
	"vec_min",
	"vec_sum",
}

var G_Group []string = []string{
	"densify(market)",
	"densify(industry)",
	"densify(subindustry)",
	"densify(sector)",
	"densify(pv13_h_f1_sector)",
}

var G_Truncation []float32 = []float32{
	0.01, 0.05, 0.1,
}

var G_Decay []int = []int{
	4, 8, 32,
}
var G_DecayStr []string = []string{
	"0", "4", "8", "16", "32", "64",
}

var G_Region []string = []string{
	"USA",
	"GLB",
	"ASI",
	"EUR",
	"CHN",
}

var G_Neutra map[string][]string = map[string][]string{
	"USA": []string{
		"INDUSTRY",
		"MARKET",
		"SECTOR",
		"SUBINDUSTRY",
		"SLOW_AND_FAST",
		"RAM",
		"STATISTICAL",
		"CROWDING",
		"FAST",
		"SLOW",
	},
	"CHN": []string{
		"INDUSTRY",
		"MARKET",
		"SECTOR",
		"SUBINDUSTRY",
		"SLOW_AND_FAST",
		"RAM",
		"CROWDING",
		"FAST",
		"SLOW",
	},
	"GLB": []string{
		"INDUSTRY",
		"MARKET",
		"SECTOR",
		"SUBINDUSTRY",
		"SLOW_AND_FAST",
		"RAM",
		"STATISTICAL",
		"CROWDING",
		"FAST",
		"SLOW",
	},
	"EUR": []string{
		"INDUSTRY",
		"MARKET",
		"SECTOR",
		"SUBINDUSTRY",
		"SLOW_AND_FAST",
		"RAM",
		"STATISTICAL",
		"CROWDING",
		"FAST",
		"SLOW",
	},
	"ASI": []string{
		"INDUSTRY",
		"MARKET",
		"SECTOR",
		"SUBINDUSTRY",
		"SLOW_AND_FAST",
		"RAM",
		"STATISTICAL",
		"CROWDING",
		"FAST",
		"SLOW",
	},
}

var G_TradeWhen []string = []string{
	"trade_when(rank(rp_css_business)>0.8,alpha,-1);",
	"trade_when(ts_rank(rp_css_business,22)>0.8,alpha,-1);",
	"trade_when(ts_rank(vec_sum(scl12_alltype_buzzvec),22)>0.9,alpha,-1);",
	"trade_when(pcr_oi_270<1,alpha,-1);",
	"trade_when(pcr_oi_270>1,alpha,-1);",
}

var G_Universe map[string][]string = map[string][]string{
	"USA": []string{
		"TOP3000",
		"TOP1000",
		"TOP500",
		"TOP200",
		"TOPSP500",
	},
	"CHN": []string{
		"TOP2000U",
	},
	"EUR": []string{
		"TOP2500",
		"TOP1200",
		"TOP800",
		"TOP400",
	},
	"GLB": []string{
		"TOP3000",
	},
	"ASI": []string{
		"MINVOL1M",
	},
}

var G_SuperSelection []string = []string{
	"1",
	"own* (1-self_correlation)",
	"own* (1-prod_correlation)",
	"own* (1-turnover)",
	"own* (1-self_correlation*turnover)",
	"own* (1-prod_correlation*turnover)",
	"own* (1-prod_correlation*turnover*self_correlation)",
	"own* (1-self_correlation)*(1-turnover)",
	"own* (1-prod_correlation)*(1-turnover)",
	"own* (1-prod_correlation)*(1-self_correlation)",
	"own* (1-prod_correlation)*(1-turnover)*(1-self_correlation)",
	"own* (1-self_correlation)*turnover",
	"own* (1-prod_correlation)*turnover",
	"x = if_else(category == \"PRICE_MOMENTUM\", 2, 1); y = if_else(category == \"PRICE_REVERSION\", 0.5, 1); z = (long_count * x * y - short_count); if_else(turnover > 0.2, nan, z)",
	"!in(datacategories, \"pv\")",
	"!in(datacategories, \"pv\") && !in(datacategories, \"analyst\")",
	"(!in(datacategories, \"pv\") && os_start_date > \"2012-06-01\") * 1/turnover",
	"(!in(datacategories, \"pv\") && os_start_date > \"2012-06-01\") * turnover",
	"(in(datacategories, \"option\") || in(datacategories, \"model\")) && (os_start_date > \"2012-06-01\") * turnover",
	"(in(datacategories, \"pv\") && os_start_date > \"2012-06-01\") * 1/turnover",
	"1/(long_count / sqrt(universe_size(universe)) )",
	"in(datacategories, \"analyst\")",
	"in(datacategories, \"pv\") && os_start_date > \"2012-06-01\"",
	"is_nan(1);# universe_size(\"minvol1m\");!in(datacategories, \"pv\") && !in(datacategories, \"analyst\")",
	"long_count / sqrt(universe_size(universe)) ",
	"long_count / sqrt(universe_size(universe)) * (turnover < 0.2)",
	"long_count / sqrt(universe_size(universe)) * (turnover > 0.15)",
	"not(in(datacategories, \"fundamental\")) * (1-self_correlation)",
	"turnover<0.1 && (os_start_date > \"2012-06-01\") * 1/turnover",
	"turnover>0.1 && turnover<0.2 && (os_start_date > \"2012-06-01\") * turnover",
	"turnover>0.15 && (os_start_date > \"2012-06-01\") * turnover",
}

var G_SuperCombo []string = []string{
	"1",
	"combo_a(alpha)",
	"stata = generate_stats(alpha);a = stata.pnl;ts_mean(a, 20)/ts_std_dev(a, 20)",
	"stata = generate_stats(alpha);a = stata.pnl;ts_mean(a, 40)/ts_std_dev(a, 40)",
	"stata = generate_stats(alpha);a = stata.pnl;ts_mean(a, 250)/ts_std_dev(a, 250)",
	"stata = generate_stats(alpha);a = stata.returns;ts_mean(a, 20)/ts_std_dev(a, 20)",
	"stata = generate_stats(alpha);a = stata.returns;ts_mean(a, 40)/ts_std_dev(a, 40)",
	"stata = generate_stats(alpha);a = stata.returns;ts_mean(a, 250)/ts_std_dev(a, 250)",
	"stats = generate_stats(alpha); innerCorr = self_corr(stats.returns, 500); ic = if_else(innerCorr == 1.0, nan, innerCorr); maxCorr = reduce_max(ic); 1 - maxCorr",
}

var G_SuperSelectionLimit []int = []int{
	10, 15, 20, 25, 30, 50,
}
var G_SuperSelectionHandle []string = []string{
	"POSITIVE",
}
